package com.chainshop.income.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chainshop.common.core.domain.pojo.RevenueRecords;
import com.chainshop.income.service.IRevenueRecordsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chainshop.common.annotation.Log;
import com.chainshop.common.core.controller.BaseController;
import com.chainshop.common.core.domain.AjaxResult;
import com.chainshop.common.enums.BusinessType;

import com.chainshop.common.utils.poi.ExcelUtil;
import com.chainshop.common.core.page.TableDataInfo;

/**
 * 收入查询Controller
 * 
 * @author hmy
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/income/records")
public class RevenueRecordsController extends BaseController
{
    @Autowired
    private IRevenueRecordsService revenueRecordsService;

    /**
     * 查询收入查询列表
     */
    @PreAuthorize("@ss.hasPermi('income:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(RevenueRecords revenueRecords)
    {
        startPage();
        List<RevenueRecords> list = revenueRecordsService.selectRevenueRecordsList(revenueRecords);
        return getDataTable(list);
    }

    /**
     * 导出收入查询列表
     */
    @PreAuthorize("@ss.hasPermi('income:records:export')")
    @Log(title = "收入查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RevenueRecords revenueRecords)
    {
        List<RevenueRecords> list = revenueRecordsService.selectRevenueRecordsList(revenueRecords);
        ExcelUtil<RevenueRecords> util = new ExcelUtil<RevenueRecords>(RevenueRecords.class);
        util.exportExcel(response, list, "收入查询数据");
    }

    /**
     * 获取收入查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('income:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {

        return success(revenueRecordsService.selectRevenueRecordsById(id));
    }

    /**
     * 新增收入查询
     */
    @PreAuthorize("@ss.hasPermi('income:records:add')")
    @Log(title = "收入查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RevenueRecords revenueRecords)
    {
        return toAjax(revenueRecordsService.insertRevenueRecords(revenueRecords));
    }

    /**
     * 修改收入查询
     */
    @PreAuthorize("@ss.hasPermi('income:records:edit')")
    @Log(title = "收入查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RevenueRecords revenueRecords)
    {
        return toAjax(revenueRecordsService.updateRevenueRecords(revenueRecords));
    }

    /**
     * 删除收入查询
     */
    @PreAuthorize("@ss.hasPermi('income:records:remove')")
    @Log(title = "收入查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(revenueRecordsService.deleteRevenueRecordsByIds(ids));
    }
}
